local skill = fk.CreateSkill{
  name = "army_of_the_dead_skill",
}

Fk:loadTranslationTable {
  [skill.name] = "亡者大军",

  ["#army_of_the_dead_skill"] = "对一名其他角色使用，亮出最后进入弃牌堆的五张牌，对其依次使用其中的【杀】",
}

skill:addEffect("cardskill", {
  prompt = "#army_of_the_dead_skill",
  can_use = Util.CanUse,
  target_num = 1,
  mod_target_filter = function (self, player, to_select, selected, card, extra_data)
    return player ~= to_select
  end,
  target_filter = Util.CardTargetFilter,
  on_effect = function (self, room, effect)
    local player = effect.from
    local to = effect.tos[1]

    local cards = {}
    local start = #room.discard_pile
    for i = start, (start - 4), -1 do
      if #room.discard_pile == 0 then break end
      table.insert(cards, room.discard_pile[i])
    end
    room:moveCardTo(cards, Card.Processing, nil, fk.ReasonJustMove, "army_of_the_dead", nil, true, player)

    for _, id in ipairs(cards) do
      if to.dead then break end
      local card = Fk:getCardById(id)
      if card.trueName == "slash" and player:canUseTo(card, to, { bypass_distances = true, bypass_times = true }) then
        room:useCard({
          card = card,
          from = player,
          tos = { to },
          extraUse = true,
        })
      end
      cards = table.filter(cards, function(c) return room:getCardArea(c) == Card.Processing end)
    end

    cards = table.filter(cards, function(c) return room:getCardArea(c) == Card.Processing end)
    if #cards == 5 then room:delay(200) end
    room:cleanProcessingArea(cards)
  end,
})

return skill